﻿Public Class TienIchDAO
    Private connect As Connect
    Private sqlstr As String
    Public Sub New()
        connect = New Connect
    End Sub

    Public Function CapNhat(ByVal emp As TienIchDTO, ByVal flag As Boolean)
        Dim matienich As String = emp.MaTienIch
        Dim ndtienich As String = emp.NoiDungTienIch
       
        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT TIENICH (MaTienIch, NoiDungTienIch)" & _
                        " VALUES('" & matienich & "', '" & ndtienich & "')"
        Else
            sqlstr = "UPDATE TIENICH SET  MaTienIch  = '" & matienich & _
                                        "', NoiDungTienIch   = '" & ndtienich & _
                                    "' WHERE MaTienIch  = '" & matienich & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function
    Public Function XoaTienIch(ByVal emp As TienIchDTO)
        Dim matienich As String = emp.MaTienIch()
        sqlstr = "DELETE TienIch WHERE MaTienIch = '" & matienich & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function GetData() As List(Of TienIchDTO)
        Dim i As Integer
        Dim matienich, ndtienich As String
        Dim tiDTO As TienIchDTO
        Dim tiList As New List(Of TienIchDTO)
        Dim dt As New DataTable
        dt = connect.GetData("select * from TIENICH")
        For i = 0 To dt.Rows.Count() - 1
            matienich = dt.Rows(i)("MaTienIch").ToString
            ndtienich = dt.Rows(i)("NoiDungTienIch").ToString
            tiDTO = New TienIchDTO(matienich, ndtienich)
            tiList.Add(tiDTO)
        Next
        Return tiList
    End Function

End Class
